home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / DWSTK / STKMAN.DOC < prev    next >
Encoding:
Text File  |  1996-10-19  |  84.0 KB  |  2,509 lines

  1.         DiamondWare's Sound ToolKit
  2.  
  3. DOS
  4. ---
  5.  
  6. Welcome to DiamondWare's Sound ToolKit (STK).  If you're a game or
  7. multimedia programmer, and you want a hassle-free, easy way to
  8. include high-quality music and digitized sound effects in your
  9. DOS products, and you don't want to pay high licensing fees or ongoing
  10. royalties, you want DiamondWare's Sound ToolKit.
  11.  
  12. Your users will enjoy programs which use DiamondWare's STK more!
  13. The STK is small and fast.  It doesn't put lots of files on the hard
  14. drive.  It can even autodetect the sound hardware's port, DMA, and
  15. IRQ settings.
  16.  
  17. The STK just works, period.  It works in Windows 3.1, Windows 95, and
  18. OS/2 DOS boxes.  It works under Novell DOS, EMM386, QEMM, 386MAX,
  19. DoubleSpace, Stacker, etc.  It works with all possible IRQs.  It's
  20. been tested with more than 35 different sound boards, and 5 brands
  21. of CPU.  And, it makes music sound better than you'd expect.  Listen
  22. for yourself!
  23.  
  24. Programmers will like the STK!    Its clean API is easy to learn, and
  25. easy to use.  The STK architecture won't force you to change your
  26. code around to accomodate it.  We even provide an optional timer
  27. module.  The documentation is so good that we're laying it bare right
  28. here, so you can read it before you spend your money.  And, should you
  29. encounter a problem, you can call DiamondWare for technical support and
  30. we'll be happy to get you up and running.
  31.  
  32. Business managers and financial officers will like it too.  The price
  33. is a low $250, with no royalties or maintenance fees.  And we stand
  34. behind our product: bug fixes are free.
  35.  
  36. Try this fully-functional demo free for 30 days.  Upload it to your
  37. favorite on-line service, and give it to your friends.
  38.  
  39. For registered users, we provide a printed manual, with two additional
  40. sections.  First, there is a chapter on music and sound production,
  41. written by a professional musician.  Second, there is documentation on
  42. our proprietary file formats (.DWM and .DWD).
  43.  
  44. We provide a fairly complete (text-mode) setup program, including source
  45. code (in C).  We provide the source code to STKRUN.EXE (in C), so if you
  46. have a 16-bit C compiler, you can change it.
  47.  
  48. We provide OPLKBD.EXE, which helps when tweaking .IBK files.  And, we
  49. provide WMS.IBK, courtesy of another professional musician.
  50.  
  51. Finally, we get rid of that annoying talking shareware message!
  52.  
  53. Windows?
  54. --------
  55.  
  56. The WIN-STK shipped in March, 1996.  It includes 16- and 32-bit DLLs,
  57. supporting Windows 3.x (including Win32s), Windows 95, and Windows NT.
  58. It supports every C/C++ compiler, Visual BASIC, Delphi, and Optima++.
  59.  
  60. Features include the ability to (reliably!) mix up to 16 WAVE files, in
  61. any combination of 8- and 16-bit, and mono or stereo, on any sound card
  62. with Windows drivers.
  63.  
  64. There is (fast!) pitch and volume change DSP integrated with the kernel.
  65.  
  66. The DLL can send a window message when a sound ends.
  67.  
  68. The WIN-STK DLL is so small and fast that you'll hardly notice it!
  69.  
  70. Check out the fully-functional WIN-STK demo, downloadable from our web
  71. site (www.dw.com).
  72.  
  73. About DiamondWare
  74. -----------------
  75.  
  76. In addition to this product, we are busily at work on other products.
  77. DiamondWare develops games as well as developer's tool kits.  Look for
  78. more exciting products soon!
  79.  
  80. We also offer a full range of consulting and software development
  81. services, from device-driver development to turnkey multimedia titles.
  82. Please call for more information.
  83.  
  84. We are also very interested in your feedback.  Please feel free to send
  85. email to keith@dw.com, with a suggestion for a future product, an idea
  86. for improving the STK, or anything else which you feel we should know.
  87.  
  88. Thank you.
  89.  
  90.                Ordering Information
  91.  
  92. DiamondWare's Sound ToolKit is available from The Coriolis Group.
  93.  
  94. To order from within the US, call (800) 410-0192.  All other locations,
  95. please call (602) 483-0192 or FAX (602) 483-0193.
  96.  
  97. Send all mail orders to:
  98.  
  99. STK Offer code LT-5
  100. Coriolis Group
  101. 7339 Acoma Drive
  102. Suite 7
  103. Scottsdale, AZ 85260
  104.  
  105.           DiamondWare's Sound ToolKit for DOS Order Form
  106.  
  107. Name ________________________________________________________________
  108.  
  109. Address _____________________________________________________________
  110.  
  111. City _______________________________ State ______ ZIP _______________
  112.  
  113. Country (if outside USA) ____________________________________________
  114.  
  115. Price of DiamondWare's Sound ToolKit                          $250.00
  116. Shipping and Handling in the US                  2.00
  117. Shipping and Handling to Canada                  5.00
  118. Shipping and Handling to other countries            10.00
  119. Arizona residents sales tax                                add $16.75
  120.  
  121. Make check payable to "Coriolis Group"   Total enclosed:  $__________
  122.  
  123. Master Card/Visa information
  124. Card number ____________________________________ Expiration _________
  125.  
  126. Legal Stuff
  127. -----------
  128. DiamondWare's Sound ToolKit (STK) was designed and developed by
  129. DiamondWare, Ltd.
  130.  
  131. This software and documentation are Copyright 1994, 1995 DiamondWare,
  132. Ltd.  All rights reserved.  DiamondWare's Sound ToolKit, DiamondWare's
  133. STK, The STK, DiamondWare, and DW are trademarks of DiamondWare, Ltd.
  134.  
  135. DiamondWare can be contacted via:
  136.    email: keith@dw.com or erik@dw.com
  137.  
  138.    voice:   (602) 917-3474
  139.    FAX:     (602) 917-5973
  140.  
  141. Credits
  142. -------
  143. DiamondWare's Sound ToolKit was designed and developed by Keith
  144. Weiner and Erik Lorenzen.
  145.  
  146. Example source code was developed by Erik Lorenzen and Keith Weiner,
  147. with language-specific help from David Johndrow (Pascal), and Don
  148. Lemons (BASIC).
  149.  
  150. This document was written by Keith Weiner, with major revisions by
  151. Eric Lund, and a chapter on music/sound development by David
  152. Schultz.  David is a professional musician and has produced music
  153. for several published games.  You can contact David via CompuServe:
  154. 72143,3624.
  155.  
  156. The protected-mode Borland Pascal module was developed by Tom
  157. Repstad and Erik Lorenzen.
  158.  
  159. Included sample MIDI song is Copyright 1994 David Schultz, All
  160. Rights Reserved.  Used by permission.  May not be used without
  161. written permission from David Schultz.
  162.  
  163. Proofreading was done by Joyce Peterson, David Ziegler, and Erik
  164. Lorenzen.
  165.  
  166. Miscellaneous utility programs which made the STK possible were
  167. written by David Ziegler.
  168.  
  169. The included FM instrument patch file is courtesy of Tim Melton.
  170. You can contact Tim via CompuServe: 72134,175.
  171.  
  172. Special thanks to Steve Blackwood, John Davis, Steve Estvanik, David
  173. Johndrow, Don Lemons, and David Schultz for testing.
  174.  
  175. 386MAX is a trademark of Qualitas Inc.
  176. Advanced Gravis and Ultrasound are trademarks of Advanced Gravis Computer 
  177. Technology Ltd.
  178. AMD is a trademark of Advanced Micro Devices Corporation
  179. Aria is a trademark of Prometheus Products Inc.
  180. Bane is a trademark of Superego Software
  181. Borland and Turbo Pascal are trademarks of Borland International Inc.
  182. Cyrix is a trademark of Cyrix Corporation
  183. IBM and OS/2 are trademarks of International Business Machines Corporation
  184. Intel is a trademark of Intel Corporation
  185. Microsoft, MS-DOS, and Windows are trademarks of Microsoft Corporation
  186. Novell DOS and Novell are trademarks of Novell Inc.
  187. OPL-2 and OPL-3 are trademarks of Yamaha Corporation
  188. QEMM is a trademark of Quarterdeck Office Systems Inc.
  189. Sound Blaster is a trademark of Creative Labs Inc.
  190. TI is a trademark of Texas Instruments Inc.
  191.  
  192.            NO-NONSENSE LICENSE AGREEMENT
  193.            -----------------------------
  194.  
  195. DiamondWare's Sound ToolKit (the STK) is copyright 1994, 1995 by
  196. DiamondWare, Ltd., of 16 Concord Drive, New City, NY 10956.
  197. Note that as of January 1, 1996, DiamondWare will be located at 2095
  198. North Alma School Road, Suite 12-288, Chandler, AZ 85224.
  199.  
  200. The STK is provided "as-is", without warranty of any kind.
  201.  
  202. This version of the STK is SHAREWARE.  DiamondWare grants you a
  203. personal license to evaluate the STK for 30 days.  This license is for
  204. evaluation purposes only.  You may not distribute this SHAREWARE
  205. version of the STK as part of any other software.  In any event, after
  206. 30 days, you must pay the license fee or stop using the STK.
  207.  
  208. DiamondWare also grants permission to distribute this SHAREWARE version
  209. of the STK under the following terms:
  210.  
  211. 1) You must include all of the files listed in PACKING.LST.
  212. 2) You must make it clear that the STK is shareware.
  213.  
  214.               All About the STK 
  215.  
  216. What Is It?  What Does It Do?
  217. -----------------------------
  218. DiamondWare's Sound ToolKit (STK) is a sound library written in 99%
  219. real-mode assembler (except for API "wrapper" functions).  It
  220. supports FM music synthesis and digital audio on Sound Blaster and
  221. compatible hardware.
  222.  
  223. The STK can play up to sixteen digital effects at the same time
  224. (called polyphony).  Unlike other sound libraries, there are no
  225. restrictions on calling INT 21h (DOS) functions.
  226.  
  227. It's linkable with any C/C++, Pascal, BASIC, or ASM program, which means
  228. adding the STK to a mostly-completed program will be easy.
  229.  
  230. The STK is built tough.  DiamondWare has acquired over thirty sound
  231. boards, fifty books (including manufacturer's specifications), four
  232. operating systems, and five brands of CPUs to test the STK during
  233. development.  All this testing means that programmers who use the
  234. STK won't field millions of tech-support calls saying "the sound
  235. doesn't work," or "it doesn't crash unless I enable the sound
  236. option."
  237.  
  238. The STK's autodetect is powerful.  It can determine the hardware
  239. type, port, DMA channel, and IRQ level automatically--under every
  240. major DOS environment (including Windows DOS boxes, OS/2 DOS boxes,
  241. Novell DOS, QEMM, 386MAX, and EMM386), running on every major brand
  242. of CPU, including Intel, AMD, Cyrix, IBM, and Texas Instruments.
  243. The STK goes directly to the sound hardware, requiring neither
  244. environment variables nor user input.  And, should you wish, you can
  245. override any setting.
  246.  
  247. The STK provides "mixer" functionality.  The better boards (Sound
  248. Blaster Pro and up) have chips on-board which can control the volume
  249. level of music and sound effects independently, and also the total
  250. volume.  For sound boards that don't have such a chip, the STK can
  251. mix levels in software.
  252.  
  253. DiamondWare's STK supports an important subset of the MIDI
  254. specification, including true dynamic patch changes, velocity
  255. sensitivity, pitch bend, and aftertouch.  Future versions of the STK
  256. will support more of the MIDI specification.
  257.  
  258. The STK doesn't allocate any memory dynamically.  It doesn't make
  259. any INT 21h calls (except during autodetect and initialization).  It
  260. doesn't require any outside code to link.  It doesn't have to
  261. reprogram the timer hardware, though it comes with optional code to
  262. do this.  The STK doesn't take hundreds of kilobytes of RAM.  It
  263. doesn't pollute your users' install directories with scores of
  264. files.  And it doesn't use a single line of code from a sound board
  265. manufacturer, or any other library vendor.
  266.  
  267. What Are Its Limitations?
  268. -------------------------
  269. The STK is a kit for Sound Blasters, SB-compatibles, and SB-clones.
  270. It will not work with the native modes of non-Creative Labs' sound
  271.  
  272. boards.  [Creative Labs is the major player in the sound board
  273. market.]  However, it has been designed and tested to work with their
  274. compatible modes, (which are often only 90-95% "compatible").
  275.  
  276. It requires a 386SX or higher processor .  This is not because it
  277. uses so much computing power (it doesn't), but because we've made
  278. extensive use of instructions and registers which are unavailable on
  279. the 286 and lower.
  280.  
  281. The STK can't play VOC files (sound effects) greater than 64k,
  282. although it supports easy sequencing of split-up VOC files.
  283.  
  284. The STK needs interrupts to remain active.  Disabling interrupts for
  285. extended periods of time will pause all sound playback, until
  286. interrupts are enabled again.  Music notes will hang, and digitized
  287. will skip and repeat like a CD player trying to track a bad disc.
  288.  
  289. The STK does not support sampling rates under 4 KHz or over 24 KHz.
  290.  
  291. The STK does not manage resource files, nor play files from disk.
  292. You must manage your directory structure, and load each file into a
  293. buffer before the STK can play it.
  294.  
  295. The STK can't change its settings (like volume levels) "in the
  296. background".  If you want to do this, then write some code that
  297. checks the current time, and slowly change the volume level.  It's
  298. no harder than moving 20 space aliens, a player, and 5 bullets.
  299.  
  300.                Before You Start
  301.  
  302. Prerequisite Knowledge
  303. ----------------------
  304. DiamondWare's STK is a programmer's library, not a game.  As such,
  305. it's a highly technical product.  While this document was written to
  306. tell you all about the STK, it can't tell you how to program.
  307. Before reading this document, you should be familiar with PC
  308. programming -- including bitwise operations and linking with external
  309. libraries.
  310.  
  311. The STK was designed to work with C/C++, Pascal, and BASIC.  Even if
  312. you will not be programming in C, several conventions and examples
  313. in this manual are given only in C, so prior C experience will be
  314. helpful.  For example, all function prototypes are given for C,
  315. Pascal, and BASIC; but in general, descriptions are given only using
  316. C terminology.  Here is a guide for Pascal and BASIC users to aid in
  317. understanding C:
  318.  
  319. All subroutines are called "functions", although in Pascal and BASIC
  320. they may be "functions", "procedures", or "subroutines".  A C
  321. struct, often called a structure, is the equivalent of a Pascal
  322. record and a BASIC TYPE.
  323.  
  324. C expresses bitwise OR as a pipe |, bitwise AND as an ampersand &,
  325. logical OR as two pipes ||, and logical AND as two ampersands &&.  C
  326. comments are either a double slash //Comment which is a comment
  327.  
  328. until the end of the line (equivalent to BASIC's apostrophe or REM)
  329. or /*Comment*/ (equivalent to Pascal's (*Comment*)).  BASIC
  330. programmers should ignore all underscores _.
  331.  
  332. There's one other important thing for Pascal and BASIC programmers
  333. to know about C.  The ampersand & operator can also be used to take
  334. the address of a variable.  For example:
  335.  
  336.         dws_MSongStatus(&mstat);
  337.  
  338. This call passes the address of the variable mstat to the function
  339. (which puts the song's status into the variable).  This is
  340. equivalent to Pascal's var or BASIC's SEG (pass by reference)
  341. calling conventions.
  342.  
  343. In specific instances, Pascal and BASIC differences with C will be
  344. explicitly listed.
  345.  
  346. Sometimes in this document, Turbo Pascal is distinguished from other
  347. languages.  This is because Pascal works with "units."  A unit
  348. contains not only the linkable program code, but also the
  349. declarations which tell the compiler about that program code and the
  350. data types it requires.  C and BASIC use a different model, in which
  351. the compiler is told to include some human-readable header file,
  352. which contains declarations of code and data types, but no more.
  353. The compiler produces a .OBJ file, which the linker puts together
  354. with other .OBJ files (and .LIB files, which are really just several
  355. .OBJ files in one) to make the final .EXE.
  356.  
  357. The Sound ToolKit is distributed with a single .LIB which works with
  358. all Microsoft languages, Borland C/C++, and Turbo Assembler.  Header
  359. files are provided for C/C++ and BASIC.  Also included are unit
  360. files for Turbo Pascal versions 6 and 7.
  361.  
  362. All source files provided on disk were produced with tabs set to 2.
  363.  
  364.                Installing the STK
  365.  
  366. Simply unzip the zip file (using Pkunzip 2.04 or higher) into a
  367. directory on your hard drive.
  368.  
  369. Make sure you put the header files and the library file (or the
  370. Pascal unit file) where the compiler and linker can find them.  If
  371. you need more information on this and related topics, your
  372. compiler's manual will be far more detailed than is possible here,
  373. and will cover your specific software environment.
  374.  
  375. You may want to put the executables (MID2DWM.EXE, VOC2DWD.EXE, etc.)
  376. in an existing binaries directory, or set the PATH environment
  377. variable to point to them.  Your MS-DOS manual describes this in
  378. detail.
  379.  
  380. Note: we provide provide batch files for building all the example
  381. programs in all languages.  Check them out.
  382.  
  383.           Additional Pascal Notes
  384.  
  385. Because there are several different file formats for Pascal units, you
  386. must rename one of the files we provide before using the STK.  If you're
  387. using Turbo Pascal 6, then please rename DWS6.TPU to DWS.TPU.  For
  388. Turbo Pascal 7 (and real-mode Borland Pascal 7), rename DWS7.TPU to
  389. DWS.TPU.  For protected-mode Borland Pascal, rename DWS7.TPP to DWS.TPP.
  390.  
  391. Note: don't bother trying to compile DWS.PAS.  The file is provided as
  392. a human-readable version of the unit, but it's not complete and it
  393. WILL NOT COMPILE.
  394.  
  395.  
  396.  
  397.             Linking With the STK
  398.  
  399. The STK has been designed so that calling it in a real-world program
  400. is relatively simple.  However, the STK is a non-trivial component
  401. of your program, and there are some non-obvious things to know.
  402.  
  403. As mentioned above, the STK works with C/C++, Pascal, and BASIC.
  404. Additionally, it should work with any other linkable language which
  405. supports the Intel/Microsoft .OBJ file format specification (such as
  406. assembler).  If you are using such a language, you will have to port
  407. the C header files to your language.  Link with DWS.LIB as you would
  408. with any other library.
  409.  
  410. By far, the easiest way to use the STK is in large model programs.
  411. In a large model program, all function calls and all data references
  412. are made via 32-bit segment:offset addresses.  The STK expects this
  413. convention.
  414.  
  415. It's possible to use the STK in mixed model programs, where some
  416. code or data is "near" and other code or data is "far."  As long as
  417. the STK's code and data is all "far," this can work.  See your
  418. compiler manual for details on how to do this.
  419.  
  420.                Protected-Mode
  421.  
  422. Version 2 supports protected-mode!  Specifically, it works with the
  423. Watcom/DOS4GW (and PMODE/W and CauseWay) and Borland/PowerPack
  424. environments.
  425.  
  426. The protected-mode version is source-compatible with real-mode.  With
  427. the exception of such real-mode constructs as _far, real-mode STK C
  428. code _IS_ protected-mode STK C code.
  429.  
  430. The core of the protected-mode STK implementation is the robust and
  431. high-quality real-mode STK kernel.  We now provide a real-mode program,
  432. STKRUN.EXE, which installs the real-mode STK kernel into residence,
  433. grabs an interrupt vector, and spawns your protected-mode application.
  434. STKRUN.C is linked with the new version of DWS.LIB, to form STKRUN.EXE.
  435. This program hooks a free interrupt vector, and spawns your protected-
  436. mode program.  Source to it is included in the registered version.
  437.  
  438. Your protected-mode program is linked with DWSP.LIB, a 32-bit flat-model
  439. module designed to accept C calls, and pass them down to real-mode via
  440. an interrupt mechanism.  It handles all real-mode to protected-mode
  441. issues transparently to the application.
  442.  
  443. In short, you can make all STK calls as you would from real mode (there
  444. are a few restrictions, listed below).  The performance of the system
  445. is actually quite good; the calls down to real-mode don't consume much
  446. CPU time.
  447.  
  448. You should be aware of four non-obvious limitations, namely:
  449.  
  450.   If music is playing, any failed call to dws_MPlay will stop it.
  451.   dwt_ calls are NOT re-entrant in protected-mode.
  452.   Each digitized sound must fit in 64K (music files may be larger).
  453.   All actively playing sounds and music must fit in real-mode memory.
  454.  
  455.            Borland Pascal Protected-Mode
  456.  
  457. Like for 32-bit C/C++ DOS extenders, STK support for the 16-bit DOS
  458. extender in Borland Pascal uses the real-mode program STKRUN.EXE (see
  459. above in this file, or the full documentation for more details).
  460.  
  461. Also like for 32-bit DOS extender support, the 16-bit protected-mode
  462. STK library is a wrapper which acts like an STK extender, accepting
  463. calls from your protected-mode program, thunking down to the real-mode
  464. kernel, and thunking any return values back up to protected-mode.
  465.  
  466. Unlike with the 32-bit C/C++ version, you must allocate memory beneath
  467. 1M for all sounds and songs.  The sample programs playdwd.pas and
  468. playdwm.pas use the routines in mem.pas to allocate and deallocate
  469. memory according to this requirement.
  470.  
  471. mem.pas uses DOSGlobalAlloc and DOSGlobalFree, respectively.
  472. DOSGlobalAlloc returns both a protected-mode selector and a real-mode
  473. segment.  The protected-mode STK library needs both values.  We've
  474. created a record, called dws_ADDRESS, to contain both fields.  In each
  475. case where an STK function needs the address of a sound/song buffer, it
  476. expects this structure.
  477.  
  478.  
  479.            Turbo Pascal Real-Mode
  480.  
  481. To accomodate Borland Pascal protected-mode, we've created a new record
  482. type, dws_ADDRESS.  The sample programs have been updated to use this.
  483. For real-mode code, however, dws_ADDRESS reduces to a simple pointer to
  484. byte (as we've used since version 1.0).  It's just something of which to
  485. be aware.
  486.  
  487.             About Music and Sound
  488.  
  489. Introduction
  490. ------------
  491. Sound, especially in the PC world, is a complicated topic.  This
  492. section will serve as an overview of the subject.  The STK provides
  493. functionality for the two primary aspects of sound programming: FM
  494. synthesis for playback of MIDI (.MID format) music, and digital
  495. audio for playback of digitally sampled (.VOC format) sound effects.
  496.  
  497. FM Synthesis
  498. ------------
  499. FM stands for "Frequency Modulation," which refers to how musical
  500. notes are created.  In FM, a sound is created from two operators,
  501. which are simple sine waves.  One operator, called the modulator, is
  502. used to modify the frequency output by the other, called the
  503. carrier.  The resulting waveform is surprisingly rich (much more so
  504. than Amplitude Modulation).  FM synthesis is a convenient method for
  505. playing music.
  506.  
  507. The waveform is put through an envelope, which alters the output
  508. volume during the four distinct phases of a musical note: attack,
  509. sustain, release, and decay.
  510.  
  511. On Sound Blasters, FM synthesis is performed by a Yamaha OPL-2 or
  512. OPL-3 chip in the digital domain.  The total output of all voices is
  513. sent to a special Yamaha Digital-to-Analog Converter (DAC), which
  514. creates low-level analog signals.
  515.  
  516. Programmed properly, the FM synthesizer can produce fairly nice
  517. instrument sounds, including surprisingly good drums.  The key
  518.  
  519. phrase here is "fairly nice." If you want to create a mood, you can
  520. do it with FM synthesis.  However, you cannot realistically
  521. reproduce the sound of most acoustic instruments (FM does a better
  522. job with "electronic" sounds).
  523.  
  524. Music is created by a musician, a computer, and sequencer software.
  525. Usually he'll use a (music) keyboard controller to enter note data,
  526. although some musicians may type it in on their computer's keyboard.
  527.  
  528. The result of the musician's toil and effort, the .MID file, is a
  529. collection of note information, but it isn't sufficient to make
  530. music; it contains no information about what the instruments should
  531. sound like.  A patch bank, which is a set of instrument definitions,
  532. fills this gap.  This nomenclature comes from the old days when
  533. technicians plugged patch cords into racks of equipment to change
  534. synthesizer sounds.  Today, patch is a synonym for a single musical
  535. instrument sound.
  536.  
  537. The OPL FM chip uses eleven parameters to describe an instrument.  A
  538. single instrument patch is therefore 11 bytes (plus a header and
  539. some waste).  Software such as Symphonix OPL Patch Editor/Librarian
  540. by Flashpoint Productions is the best way to tinker with patches.
  541.  
  542. Collections of patches are stored in instrument bank files (.IBK
  543. format).  Although you can put any instrument at any index in the
  544. file, you're going to discover that only songs custom-written for
  545. that instrument bank file will play correctly.  Other songs will
  546. probably sound totally unacceptable.
  547.  
  548. Enter the General MIDI standard, which specifies all 128 patches
  549. (e.g. instrument 1 is Grand Piano).  Although, for FM synthesis,
  550. General MIDI compliance is not required, we strongly recommend it.
  551. When the industry moves to wavetable boards, your music will sound
  552. good on most boards.  (Eventually, sound hardware will support
  553. General MIDI and wavetable.  But today's installed base is mostly
  554. FM.  Sales of FM hardware are still much higher than wavetable.
  555. Wavetable sales are projected to surpass FM sales in 1996.  Wavetable
  556. installations will surpass FM no earlier than 1997.  Considering this,
  557. and the fact that many wavetable boards also include or emulate FM, we
  558. believe FM is far more important than wavetable right now.  Good FM is
  559. currently a big market advantage.)
  560.  
  561. Potential Music Problems
  562. ------------------------
  563. The STK music playback engine may behave differently than you'd expect.
  564. The following is a brief discussion of two bona fide features which may
  565. cause some unexpected problems.
  566.  
  567. The STK is extremely sensitive to velocity.  If you play a song and the
  568. drums or an instrument sound faint (or loud), this is why.  Change the
  569. output level of the instrument patch, or use your sequencer to bring up
  570. the volume of the problem track.
  571.  
  572. The STK will allow notes of bells and strings to "ring out" after they are
  573. "key released".  If this is causing undesired effects, simply make your
  574. instrument patches "sustaining".  The STK will shut such notes down
  575. immediately when they are released.
  576.  
  577. Digital Audio
  578. -------------
  579. In digital audio, an analog waveform is translated into the digital
  580. domain by sampling (i.e. measuring) the amplitude of the wave at
  581. regular intervals.  The sampling rate is the frequency at which this
  582. is done.
  583.  
  584. As Nyquist proved, the sampling rate must be at least twice as high
  585. as the highest frequency in the waveform being sampled, or else
  586. aliasing occurs.  When this happens, the sound takes on an
  587. unpleasant metallic overtone.
  588.  
  589. Let's say you're recording the sound of glass breaking, which
  590. includes some very high frequencies -- we'll assume up to about 11
  591. KHz.  Unless you're using a low-pass analog filter (the Sound
  592. Blasters have several) to cut out high frequencies, you should
  593. sample at 22 KHz or higher.
  594.  
  595. Note: sampling at very low rates will have undesirable side-effects.
  596. Speech will be lisped, and in general, everything will sound dull.
  597.  
  598. Dynamic range, which is the difference between the softest and
  599. loudest sounds, is also important.  16-bit samples sound better than
  600. 8-bit samples because the extra byte allows more precision, and more
  601. contrast between soft and loud.
  602.  
  603. It is important to record your sound effects at a low volume, if you
  604. plan on playing more than one or two simultaneously.  You can also
  605. compress the dynamic range when you prepare the sound.  This will
  606. help you avoid clipping (i.e. exceeding the dynamic range of the
  607. playback hardware).
  608.  
  609.                General Guidelines
  610.  
  611. Don't Touch That Compiler Yet!
  612. ------------------------------
  613. Before you can bring sound into your program, you must convert the
  614. .MID and .VOC files into formats that are quickly and easily parsed
  615. at run-time.  Use MID2DWM and VOC2DWD, respectively.  See the
  616. Utilities heading in the Reference section for more information on
  617. how to use these programs.
  618.  
  619. The Autodetect
  620. --------------
  621. Before you can initialize the STK, you must know the sound hardware
  622. settings: base port, DMA channel, and IRQ level.  The STK provides an
  623. autodetect routine to determine these.
  624.  
  625. Using the autodetect is easy.  Create two structs, one of type
  626. dws_DETECTOVERRIDES, and the other of type dws_DETECTRESULTS.  Set
  627. the baseport, digdma, and digirq fields of the overrides struct to
  628. 65535 (to autodetect them), or initialize them with their correct
  629. values.  Either way, call dws_DetectHardWare, passing the address of
  630. both structs as parameters.  The results struct will be filled in.
  631.  
  632. Note: you must call dws_DetectHardWare even if you know these values
  633. in advance.  The reason is that it stores information in the
  634. reserved field of the dws_DETECTRESULTS struct.
  635.  
  636. Note: If you write the settings to a disk file, make sure you write
  637. the entire struct.  dws_Init requires the information in the reserved
  638. field and may crash if it's not there.
  639.  
  640. For more information about these and other structures, see Data
  641. Structures in the Reference section.
  642.  
  643. Many sound boards require the user to load drivers from either
  644. CONFIG.SYS or AUTOEXEC.BAT (e.g. the Advanced Gravis Ultrasound and
  645. SBOS) These drivers must be loaded before any STK-enabled software
  646.  
  647. is run.  If their drivers aren't loaded, some boards may not respond,
  648. or worse yet, could take on default values which conflict with other
  649. hardware.  This last case is a major potential problem and could
  650. cause a crash.
  651.  
  652. In the overwhelming majority of cases, the autodetect will quietly
  653. do its job.  It is robust, and there are only two known (obscure)
  654. failure cases.  If you find any others, please report them to
  655. DiamondWare!
  656.  
  657. The first failure case occurs only when the STK is running in a
  658. Microsoft Windows Enhanced-mode DOS box.  If the user has another
  659. card which is constantly doing DMA on an 8-bit channel, the STK will
  660. crash the machine.  The only card known to do this is the NE2100 bus
  661. mastering ethernet adapter, which uses a 16-bit DMA channel 99% of
  662. the time.  (It's an expensive, high-performance card; running it on
  663. an 8-bit DMA channel is like putting 85-octane gas into a sports
  664. car.)  Other devices that use DMA, like CD-ROM and SCSI controllers,
  665. do not perform DMA transfers unless they are in use, and will not
  666. cause any problems with the STK.
  667.  
  668. The second failure case occurs only with Aria 16 and Aria 16se
  669. cards.  If the Sound Blaster portion of the board is configured for
  670. IRQ 2/9, the autodetect will incorrectly return the IRQ used by the
  671. MIDI portion of the board, rather than that of the digitized
  672. portion.
  673.  
  674. Initializing the STK
  675. --------------------
  676. After calling dws_DetectHardWare, you'll need a struct of type
  677. dws_IDEAL.  Its fields are requests for STK services.  Set each to
  678. the desired values.  Then call dws_Init, passing the address of the
  679. dws_DETECTRESULTS and dws_IDEAL structs as parameters.
  680.  
  681. This struct is here for three reasons.  The first is to tell the STK
  682. the initial sampling rate you want.  The second reason is to
  683. conserve CPU cycles.  The STK will run faster with fewer digital
  684. voices.  The last reason is that future versions of the STK will
  685. offer more features (e.g. 16-bit, stereo, etc.)  You may not want
  686. some or all of these services.  Initialize this struct properly, and
  687. you will easily incorporate STK upgrades into your programs.
  688.  
  689. When the STK initializes, it resets the sound hardware to a 100%
  690. known state, including setting the mixer to maximum volume.  It also
  691. sets up its own internal data structures, Interrupt Service Routines
  692. (ISRs), etc.  Few STK functions will work until you call dws_Init.
  693.  
  694. The Hardware Timer
  695. ------------------
  696. Next, initialize the hardware timer.  The STK must be called at a
  697. relatively high rate.  The DiamondWare Timer (DWT) module will do
  698. the trick, or you can use your own code.
  699.  
  700. If you're going to use the DWT, call dwt_Init, passing it a rate
  701. constant as a parameter.  The DWT will do all timing functions
  702. necessary to the STK (and keep time for your game, too).  See
  703. dwt_Init in the Function Reference for complete information.
  704.  
  705. If you have your own code, initialize it now.  Make sure it will
  706. call dws_Update once during each hardware timer interrupt.  The DWT
  707. will not interfere, or even link into your application.
  708.  
  709. Initiating Playback
  710. -------------------
  711. To play a song, first allocate a buffer large enough to hold the
  712. .DWM file, and then read it in.  Create a struct of type dws_MPLAY;
  713. set the track field to point to this buffer, and the count field to
  714. the number of times to play.  Now call dws_MPlay.  The song will
  715. play in the background.
  716.  
  717. To play a sound effect, allocate a buffer, and read in the .DWD
  718. file.  Create a struct of type dws_DPLAY; set the snd field to point
  719. to the buffer, the count field to the number of times to play,
  720. ignore priority field (for now), and set the presnd field to 0 (for
  721. now).  Now call dws_DPlay.  The sound will play in the background.
  722.  
  723. For more information on these structs and calls, see the Advanced
  724. Tutorial section, or The Functions heading and The Data Structures
  725. heading in the Reference section.
  726.  
  727. Note to BASIC users: make sure that your buffers don't move around
  728. during "garbage collection".
  729.  
  730. The Rules of the Game
  731. ---------------------
  732. The STK can play one music track, and up to sixteen sound effects
  733. (at the same sampling rate) at the same time.  Once a song or sound
  734. is playing, you can let it play without doing anything else.  You
  735. can even make DOS calls.
  736.  
  737. In the mode used by the STK, the FM chip allows up to 6 musical
  738. instruments and 5 drums to play simultaneously.  Drums can play and
  739. replay, still sounding good, but it's important that your music
  740. sound (and/or sustain) no more than 6 melody notes at a time.  The
  741. STK player will automatically drop notes out (though it won't
  742. crash), but a musician would inevitably make a better decision as to
  743. which notes are important than any computer algorithm.
  744.  
  745. There are five drums built in to the STK, chosen as a reasonable
  746. compromise: bass drum, snare, hi-hat, tom-tom, and top cymbal.
  747. All other drums are mapped to these five.
  748.  
  749. The STK will refuse to exceed the dynamic range of the hardware it's
  750. playing on.  This means that if you try to play 4 sound effects
  751. which all use the full 8 bits of dynamic range, you'll only hear the
  752. one with the highest priority.  Until it ends, the others will not
  753. be played, although they will continue to advance silently.  If the
  754. sound with the highest priority ends, any remaining sounds are added
  755. back in, to the limit of the dynamic range of the playback hardware.
  756.  
  757. Playback Status
  758. ---------------
  759. The functions dws_MSongStatus and dws_DSoundStatus determine whether
  760. a song or sound is playing or finished.  Each of these functions
  761. requires you to create a status variable for them to use.  To get
  762.  
  763. the status of your music, pass the address of the status variable to
  764. dws_MSongStatus.  To query the status of a specific sound effect,
  765. pass the address of the status variable, as well as its ID (from the
  766. soundnum field of its dws_DPLAY structure) to dws_DSoundStatus.
  767.  
  768. Each bit of the status variable is a flag.  Perform a bitwise and
  769. between the status variable and the playback condition you would
  770. like to test.  For example, dws_MSONGSTATUSPLAYING & status
  771. evaluates to a 1 if the music is still playing, and
  772. dws_DSOUNDSTATUSPLAYING & status evaluates to a 1 if the sound
  773. effect is still playing.  For a complete list of conditions, refer
  774. to both routines in the The Functions heading in the Reference
  775. section.
  776.  
  777. Keeping Time
  778. ------------
  779. The DWT provides a double-word (32 bit, unsigned) timer, which
  780. begins at 0 when DWT is initialized, and increments once per timer
  781. interrupt.  Calling dwt_MasterTick returns the number of clock ticks
  782. since time began (i.e.  when you called dwt_Init).  dwt_Pause and
  783. dwt_UnPause suspend and restart the master clock, respectively.
  784. They don't affect either music or digitized sound playback.
  785.  
  786. Tracking Errors
  787. ---------------
  788. Most functions in the STK return a word (16-bit, unsigned) value.
  789. This is a boolean value, indicating the success/failure of the
  790. function.  True (1) is success, and false (0) means that an error
  791. has occured.  In the case of an error, call dws_ErrNo to determine
  792. what happened.
  793.  
  794. dws_ErrNo behaves much like the errno variable in the C standard
  795. library.  Initially it's 0, and it's only changed when a function
  796. encounters an error.  It's important to check it after each call
  797. which fails, or else you won't know which one generated the error.
  798. Under The Functions, in the Reference section, there is a list of
  799. errors for each function.  You may assume this list is exhaustive;
  800. if an error isn't listed for a given function, then that function
  801. cannot generate that error.
  802.  
  803. Stopping Playback
  804. -----------------
  805. Call dws_MPause or dws_MUnPause to suspend or restart music
  806. playback.  Call dws_MClear to stop the current song.  Make sure you
  807. stop music playback before you deallocate the song buffer.
  808.  
  809. Call dws_DPause or dws_DUnPause to suspend or restart all digitized
  810. sound playback.  Call dws_DClear to stop all currently-playing
  811. sounds.  Call dws_DDiscard to stop a particular sound from playing;
  812. this function requires the sound's ID as a parameter (from the
  813. soundnum field of its dws_DPLAY structure).  Call dws_DDiscardAO to
  814. stop all occurrences of a digitized sound; this function requires a
  815. pointer to the sound's buffer.
  816.  
  817. Shutting Down
  818. -------------
  819. Before exiting to DOS, you must clean up.  First, call dwt_Kill (or
  820. shut down your own timer module).  Next, call dws_Kill.  Finally,
  821. deallocate any buffers you may have allocated during execution.
  822.  
  823. There is a problem in Microsoft Windows Enhanced-mode DOS boxes when
  824. the sound board is set to IRQ 2/9, and Windows isn't configured for
  825. the sound board.  The first time an STK-using program runs in this
  826. environment, it will work perfectly.  But if the user exits the
  827. STK-using program, and restarts it before restarting Windows, there
  828. will be no digitized sound (FM music will play normally).
  829.  
  830. Re-entrancy
  831. -----------
  832. The STK is re-entrant.  You can call its functions from your ISR's
  833. (interrupt service routines).  Just make sure you heed the dws_BUSY
  834. error.  If this occurs, make the call again later.
  835.  
  836.               Tutorial 
  837.  
  838. This tutorial will walk you through MINAPP.C, an application
  839. framework which fulfills the minimum requirements for implementing
  840. the STK in a program.  It is intended for learning the basics; it
  841. does not check for STK errors at all.  The source code for the
  842. sample applications PLAYDWD, PLAYDWM, and FINDSB are provided in C,
  843. Pascal, and BASIC on disk.  They include (more) robust
  844. error-checking, and are highly commented.  Please review them also.
  845.  
  846. Setting Up:  Includes and Variables
  847. -----------------------------------
  848. #include <stdio.h>
  849. #include <malloc.h>
  850. #include "dws.h"
  851. #include "dwt.h"
  852.  
  853. void main (void)
  854. {
  855.     FILE *fp;
  856.     byte __far *sound, *song;
  857.     word mstatus, dstatus, msize, dsize;
  858.     dws_DETECTOVERRIDES dov;
  859.     dws_DETECTRESULTS   dres;
  860.     dws_IDEAL ideal;
  861.     dws_MPLAY mplay;
  862.     dws_DPLAY dplay;
  863.  
  864. The standard C header file stdio.h is included for the file I/O
  865. functions, and malloc.h to support dynamic memory allocation.  dws.h
  866. contains all the STK prototypes, #defines, structures, and type
  867. definitions.  dwt.h provides the same, for the DWT.
  868.  
  869. MINAPP loads one sound effect, and one piece of music.  sound, a
  870. pointer, holds the address of the sound effect buffer; song, another
  871. pointer, holds the address of the music buffer.  dplay, a struct,
  872. holds all information needed to play the sound effect; mplay,
  873. another struct, holds information for playing the song.  dov, dres,
  874. and ideal are structs required for initialization.
  875.  
  876. Loading Songs and Sounds
  877. ------------------------
  878. /* ALLOCATE MEMORY FOR SOUND FILE AND LOAD IT */
  879.     fp = fopen("minapp.dwd", "rb");
  880.     fseek (fp, 0L, SEEK_END);
  881.     sound = _fmalloc (dsize=ftell (fp));
  882.     fseek (fp, 0L, SEEK_SET);
  883.     fread (sound, dsize, 1, fp);
  884.     fclose (fp);
  885.  
  886. /* ALLOCATE MEMORY FOR SONG FILE AND LOAD IT */
  887.     fp = fopen("minapp.dwm", "rb");
  888.     fseek (fp, 0L, SEEK_END);
  889.     song = _fmalloc (msize=ftell (fp));
  890.     fseek (fp, 0L, SEEK_SET);
  891.     fread (song, msize, 1, fp);
  892.     fclose (fp);
  893.  
  894. These two sections allocate buffers to store the music and the
  895. sound, then read the files into them.  minapp.dwm began life as
  896. minapp.MID and gm.ibk, and was converted by MID2DWM.  minapp.dwd
  897. began as MINAPP.VOC, and was converted by VOC2DWD.
  898.  
  899. Initializing the STK
  900. --------------------
  901. /* AUTODETECT SOUND CARD */
  902.     dov.baseport = 65535;
  903.     dov.digdma   = 65535;
  904.     dov.digirq   = 65535;
  905.     dws_DetectHardWare (&dov, &dres);
  906.  
  907. /* INITIALIZE DIAMONDWARE STK SYSTEM */
  908.     ideal.musictyp   = 1;
  909.     ideal.digtyp     = 8;
  910.     ideal.digrate    = 10989;
  911.     ideal.dignvoices = 16;
  912.     ideal.dignchan   = 1;
  913.     dws_Init (&dres, &ideal);
  914.  
  915. Notice how all fields in the struct, dov, are set to 65535.  This
  916. tells dws_DetectHardWare to autodetect the corresponding sound
  917. hardware parameters.  The results of this are returned in the dres
  918. struct.  We initialized the ideal struct to request the desired STK
  919. services (in this case overkill, since we only need one digitized
  920. voice).  When we call dws_Init, the sound hardware and the STK are
  921. set up for business.
  922.  
  923. Optional Timer Module
  924. ---------------------
  925. /* INITIALIZE OPTIONAL TIMER MODULE */
  926.     dwt_Init (dwt_72_8HZ);
  927.  
  928. A PC bootstraps (starts up) with a rate of 18.2 clock ticks per
  929. second, but the STK requires a higher rate.  Just as importantly,
  930. the STK must be called during each clock tick.  The DiamondWare
  931. Timer module will do this.  We recommend 72.8 Hz, a good compromise
  932. between music quality and Windows DOS-box compatibility.  (If you
  933.  
  934. don't care about Windows DOS boxes, use 145.6 Hz.)
  935.  
  936. Preparing Songs and Sounds
  937. --------------------------
  938. /* PREPARE SONG FOR PLAYING */
  939.     mplay.track = song;
  940.     mplay.count = 1;
  941.  
  942. /* PREPARE SOUND FOR PLAYING */
  943.     dplay.snd      = sound;
  944.     dplay.count    = 1;
  945.     dplay.priority = 1000;
  946.     dplay.presnd   = 0;
  947.     dws_DGetRateFromDWD (dplay.snd, &ideal.digrate);
  948.     dws_DSetRate (ideal.digrate);
  949.  
  950. The mplay struct is set up so that a call to dws_MPlay will play the
  951. song once.  The dplay struct is also set up.  A priority of 1000 is
  952. arbitrarily chosen, but since no other sound effects will be playing
  953. in MINAPP, this field has no practical effect.  The presnd field is
  954. also unused (set to 0), because this example does not sequence
  955. digital sounds.  The current playback rate is set to the sampling
  956. rate at which the sound was recorded.
  957.  
  958. Initiating Playback
  959. -------------------
  960. /* PLAY SONG AND SOUND ONCE */
  961.     dws_MPlay(&mplay);
  962.     dws_DPlay(&dplay);
  963.  
  964. A call to dws_MPlay starts the music, and a call to dws_DPlay begins
  965. playback of the digitized sound effect.
  966.  
  967. Wait 'Til the Fat Lady Stops Singing
  968. ------------------------------------
  969. /* MAIN LOOP */
  970.     do
  971.     {
  972.     dws_DSoundStatus(dplay.soundnum, &dstatus);
  973.     dws_MSongStatus(&mstatus);
  974.     }
  975.     while ((mstatus & dws_MSONGSTATUSPLAYING) ||
  976.        (dstatus & dws_DSOUNDSTATUSPLAYING));
  977.  
  978. We query the song and sound status.  The status is placed in a
  979. bitfield variable, via its address.  In the case of the music, we're
  980. interested in the dws_MSONGSTATUSPLAYING field; in the case of the
  981. digitized sound effect, we're interested in the
  982. dws_DSOUNDSTATUSPLAYING.  When this field is 1, it means that the
  983. song or sound, respectively, is playing.
  984.  
  985. Shutting Down
  986. -------------
  987. /* CLEAR ALL ALLOCATED MEMORY */
  988.     _ffree (song);
  989.     _ffree (sound);
  990.  
  991. /* DE-INITIALIZE STK */
  992.     dwt_Kill();
  993.     dws_Kill();
  994. }
  995.  
  996. The buffers containing the music and sound effect are now
  997. deallocated.  Normally, dws_DClear and dws_MClear would be called
  998. before freeing these buffers, but since we know that no sounds are
  999. playing at the moment, the calls are unnecessary.  The DWT is
  1000. de-initialized first by calling dwt_Kill, then the entire STK engine
  1001. is shut down by calling dws_Kill.  That's it!
  1002.  
  1003.             Advanced Tutorial 
  1004.  
  1005. Working with the Advanced Features
  1006. ----------------------------------
  1007. The example code fragments below illustrate sequencing and polyphony. We 
  1008. assume that the STK has been initialized.  sfx1 and sfx2 are digital sounds in
  1009. memory.  The following shows how the two dws_DPLAY structures are set up:
  1010.  
  1011.     dplay1.snd      = sfx1;
  1012.     dplay2.snd      = sfx2;
  1013.     dplay1.count    = 1;
  1014.     dplay2.count    = 1;
  1015.     dplay1.priority = 500;
  1016.     dplay2.priority = 1000;
  1017.     dplay1.presnd   = 0;
  1018.     dplay2.presnd   = 0;
  1019.  
  1020. Each sound effect is set to play once, and the second sound is given
  1021. a higher priority than the first.  The presnd field of both structs
  1022. is not set for sequencing.
  1023.  
  1024. Sequencing
  1025. ----------
  1026. The presnd field allows you to sequence sounds to play one after the
  1027. other.  The first sample of the second sound plays after the last
  1028. sample of the first sound.  The effect is that of a single sound,
  1029. playing seamlessly.
  1030.  
  1031. This feature is useful if you want to break a long sound into
  1032. several pieces which can fit into memory.  Or a sound may have
  1033. several different continuations, depending on player input (e.g.  a
  1034. gun fires, continuing with either a scream or a ricochet, depending
  1035. on whether the bullet hits).
  1036.  
  1037. Set the presnd field of a dplay struct to the soundnum of the sound
  1038. you want to sequence after, or use 0 if the sound is stand-alone.
  1039.  
  1040. Note: if you specify a non-zero sound number (which corresponds to a
  1041. sound actually playing), the value returned in soundnum is the same
  1042. as the value specified in presnd.  The new sound will not play
  1043. immediately, but will wait until the first sound is done.
  1044.  
  1045. The priority field is not related to sequencing.
  1046.  
  1047.     dws_DPlay(&dplay1);
  1048.     dplay2.presnd = dplay1.soundnum;
  1049.     dws_DPlay(&dplay2);
  1050.  
  1051. This plays dplay1 followed by dplay2.  If you are sequencing more
  1052. than two sounds, call dws_DSoundStatus to determine when it's safe
  1053. to sequence each sound after the second.
  1054.  
  1055. Polyphony
  1056. ---------
  1057. To play multiple digital sounds, call dws_DPlay more than once.
  1058.  
  1059. The presnd field has no bearing on polyphony.
  1060.  
  1061.     dws_DPlay(&dplay1);
  1062.     dws_DPlay(&dplay2);
  1063.  
  1064. The sounds start simultaneously.  dplay1, the first sound, has a
  1065. priority of 500.  dplay2 has a priority of 1000.
  1066.  
  1067. These numbers are arbitrary; it is the relationship between them
  1068. that counts.  Priorities of 1 and 2 will have the same results.
  1069.  
  1070. Note: if these two sounds together do not exceed the dynamic range
  1071. of the hardware, they'll both play.  However, if the total dynamic
  1072. range used by both sounds exceeds 8 bits, then you will hear only
  1073. the second sound (its priority is higher).  If the second sound is
  1074. shorter, then the first sound will be heard when the second one
  1075. ends.  Until then, it will advance silently.
  1076.  
  1077. Autodetection and Setup Programs
  1078. --------------------------------
  1079. Finding the user's sound board is non-trivial, because the user often
  1080. doesn't even know what brand he owns, let alone its settings.  So the STK
  1081. asks the hardware directly.
  1082.  
  1083. It does a good job, but there are some potential problems.  Sometimes, the
  1084. STK may be unable to find one or more sound hardware parameters (almost
  1085. always the problem lies with finding the DMA channel).
  1086.  
  1087. The capability field in the dws_DETECTRESULTS struct will tell you if the
  1088. STK found everything it needed for music and for digitized.  If both
  1089. capability flags are set, then you have nothing further to do; music and
  1090. sound will work.
  1091.  
  1092. However, only the dws_capability_FM flag might be set.  This may be because
  1093. the user has music-only hardware, or it may be that (for example) the STK
  1094. was unable to find the DMA channel.  To tell the difference, look at the
  1095. baseport field of the dws_DETECTRESULTS struct.  If this field returns as
  1096. either 65535 or 388h, this means that no digitized-capable sound hardware
  1097. is present (or the user's drivers aren't installed).  If this field returns
  1098. with any other value, it means that digitized hardware exists.  Look at the
  1099. digirq and digdma fields.  If either or both of these are set to 65535, it
  1100. means that the STK couldn't autodetect them (and the BLASTER environment
  1101. variable was either not present, or was wrong).
  1102.  
  1103. Planning ahead for this, you should have a screen where the user can type in
  1104. port, DMA, and IRQ channel.  Don't require him to do this, but make this
  1105. option available.  Take the settings you are given, and plug them into the
  1106. dws_OVERRIDES struct.  Then call dws_DetectHardWare again.
  1107.  
  1108. Don't simply look at the capability field of the dws_DETECTRESULTS.  Its
  1109. boolean flags simply indicate whether or not we figured out everything we
  1110. needed to know about music and digitized sound.  It can't tell you, for
  1111. example, if we have a port and an IRQ level, but no DMA channel.  To
  1112. determine this, look at the baseport, digdma, and digirq fields.  If baseport
  1113. is 65535 (or 388h), then we found no digitized capability.  It's virtually
  1114. certain that none is present.  If baseport is 220h, digdma is 65535 and
  1115. digirq is 7, then we couldn't determine the DMA channel.  Ask the user!  It
  1116. beats dimming out your sound option.
  1117.  
  1118. We provide a new example program to registered users: SETUP.C, which handles
  1119. setup of sound settings, and configuration files.  It isn't pretty (using
  1120. just printf and scanf), but it illustrates some important concepts.
  1121.  
  1122.               Reference
  1123.  
  1124. This section of the manual is broken down into several headings: The
  1125. Functions, The Errors, The Data Structures, The Utilities, and The
  1126. File Formats.
  1127.  
  1128.             The Functions
  1129.  
  1130. Preamble
  1131. --------
  1132. There are two headers provided with the STK.  The first is for the
  1133. sound library (DWS.H for C and DWS.BI for BASIC), and the other for
  1134. the DiamondWare Timer module (DWT.H for C and DWT.BI for BASIC).
  1135.  
  1136. For Turbo Pascal version 6 and 7, there are two .TPU files provided.
  1137. Additionally, although it's not strictly necessary, DWS.PAS (which
  1138. also contains the timer module) is provided so you can see how
  1139. everything is declared.  The sound library header declares the
  1140. constants for each error the STK can generate, some bit field
  1141. constants, the data structures used by the STK, and the prototypes
  1142. of the functions.
  1143.  
  1144. This is a complete list, in alphabetical order, of functions
  1145. provided by the STK and the optional timer module.  Each function
  1146. will be listed with a general description, as well as the
  1147. declaration syntax (prototype) for C, Pascal, and BASIC (in that
  1148. order), parameters, return value, possible error conditions, and
  1149. related functions.
  1150.  
  1151. Most STK functions have a boolean return value to indicate success
  1152. (true), or error (false).  If an error occurs, call dws_ErrNo to
  1153. determine what happened.  Unless otherwise noted, the STK will
  1154. perform no action during any call which returns an error, including
  1155. modifiying structs -- all return values are undefined.
  1156.  
  1157. Most errors are provided to help you integrate the STK into your
  1158. application; once your program is stable, you should not expect to
  1159. see any errors occur.
  1160.  
  1161. All functions and all pointers are far.  All functions use the
  1162. Pascal calling convention.
  1163.  
  1164. The Optional Timer Module
  1165. -------------------------
  1166. If you have written your own hardware timer code which reprograms
  1167. the timer rate, then you don't need the DWT.  Simply don't call our
  1168. module, and it won't link into your application.
  1169.  
  1170. The DWT reprograms the hardware timer to run at a much faster rate
  1171. than normal, while keeping the DOS and BIOS clocks happy by calling
  1172. them at 18.2 Hz (like they expect).  The DWT makes the call to
  1173. dws_Update, which is required to keep the STK happy.  And DWT will
  1174. also keep time in a way useful for video games and multimedia
  1175. applications.  Even if the user has no sound hardware installed, you
  1176. can still use DWT for its timing functions without any ill effect.
  1177.  
  1178. dws_DClear
  1179.  
  1180.     Prototypes
  1181.  
  1182.     word dws_DClear(void);
  1183.     function dws_DClear : word;
  1184.     DECLARE FUNCTION dwsDClear% ALIAS "DWS_DCLEAR" ()
  1185.  
  1186.     Description
  1187.     
  1188.     This function stops all digitized sounds from playing.  Returns
  1189.     success, even if no sounds are currently playing.
  1190.  
  1191.     Parameters
  1192.     
  1193.     None.
  1194.  
  1195.     Return value
  1196.     
  1197.     Boolean success.
  1198.  
  1199.     See also
  1200.     
  1201.     dws_DPause, dws_DDiscard, 
  1202.     dws_DDiscardAO, dws_DPlay
  1203.  
  1204.     Errors
  1205.  
  1206.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1207.     dws_NOMEM
  1208.  
  1209. dws_DDiscard
  1210.  
  1211.     Prototypes
  1212.  
  1213.     word dws_DDiscard(word sndnum);
  1214.     function dws_DDiscard(sndnum : word) : word;
  1215.     DECLARE FUNCTION dwsDDiscard% ALIAS
  1216.     "DWS_DDISCARD" (BYVAL sndnum%)
  1217.  
  1218.     Description
  1219.     
  1220.     This function shuts off a single sound instance.
  1221.  
  1222.     If you attempt to discard a sound which is not currently
  1223.     playing, this function will return success.
  1224.  
  1225.     Parameters
  1226.     
  1227.     sndnum is the sound you wish to discard, from the sound's
  1228.     dws_DPLAY structure.
  1229.  
  1230.     Return value
  1231.  
  1232.     Boolean success.
  1233.  
  1234.     See also
  1235.  
  1236.     dws_DDiscardAO, dws_DPause, dws_DClear, dws_DPlay
  1237.  
  1238.     Errors
  1239.  
  1240.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1241.     dws_NOMEM
  1242.  
  1243. dws_DDiscardAO
  1244.  
  1245.     Prototypes
  1246.  
  1247.     word dws_DDiscardAO(byte *snd);
  1248.     function dws_DDiscardAO(snd : dws_ADDRESS) : word;
  1249.     DECLARE FUNCTION dwsDDiscardAO% ALIAS
  1250.     "DWS_DDISCARDAO" (BYVAL snd&)
  1251.  
  1252.     Description
  1253.     
  1254.     This function discards all occurrences of one sound effect (.DWD
  1255.     file) that is currently playing.  If you are playing the same
  1256.     sound effect several times, this is an easy way to stop them
  1257.     all -- useful before you deallocate the sound's memory buffer,
  1258.     for example.
  1259.  
  1260.     This function requires that you specify the sound by the address
  1261.     of its buffer in memory.
  1262.  
  1263.     Note: if any sound killed by this function has a sequenced sound
  1264.     waiting to play after it, the sequenced sound will be killed
  1265.     also.
  1266.  
  1267.     Parameters
  1268.     
  1269.     snd is a pointer to the buffer storing the .DWD sound effect.
  1270.  
  1271.     Return value
  1272.  
  1273.     Boolean success.
  1274.  
  1275.     See also
  1276.  
  1277.     dws_DDiscard, dws_DPause, dws_DClear, dws_DPlay
  1278.  
  1279.     Errors
  1280.  
  1281.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_D_NOTADWD,
  1282.     dws_D_NOTSUPPORTEDVER, dws_D_INTERNALERROR, dws_BUSY,
  1283.     dws_NOTRESIDENT, dws_NOMEM
  1284.  
  1285. dws_DetectHardWare
  1286.  
  1287.     Prototypes
  1288.  
  1289.     word dws_DetectHardWare(dws_DETECTOVERRIDES *dov,
  1290.     dws_DETECTRESULTS *dr); function dws_DetectHardWare(dov :
  1291.     dws_DOPTR; dr :dws_DRPTR) : word; DECLARE FUNCTION
  1292.     dwsDetectHardWare% ALIAS "DWS_DETECTHARDWARE" (SEG dov AS
  1293.     dwsDETECTOVERRIDES, SEG dr AS dwsDETECTRESULTS)
  1294.  
  1295.     Description
  1296.  
  1297.     This is the STK's hardware autodetect.  It detects card
  1298.     settings, or verifies settings you put in dov.  Upon return, dr
  1299.     will be filled with the autodetection results.  DiamondWare
  1300.     recommends calling this function at the beginning of your
  1301.     program, each time it is run, so that if the user changes
  1302.     hardware settings between runs, your program will still work.
  1303.  
  1304.     Parameters
  1305.  
  1306.     dov is a pointer to a dws_DETECTOVERRIDES struct.  Set every
  1307.     field with either a 65535 (to autodetect), or an override (user
  1308.     setting).  User setting values will be accepted on faith (sort of).
  1309.  
  1310.     dr is a pointer to a dws_DETECTRESULTS structure, where the
  1311.     function will return its results.
  1312.  
  1313.     The reserved array in this struct holds important information;
  1314.     if you write the contents of the struct out to a file, write the
  1315.     entire struct!  dws_Init requires all of this information;
  1316.     without it, the STK could crash the computer.
  1317.  
  1318.     The bitfield capability indicates supported features:  
  1319.  
  1320.     0                                       //no sound hardware
  1321.     dws_capability_FM                       //music
  1322.     dws_capability_DIG                      //digitized sounds
  1323.     dws_capability_FM | dws_capability_DIG  //Both
  1324.  
  1325.     Return value
  1326.  
  1327.     Boolean success.
  1328.  
  1329.     See also
  1330.  
  1331.     dws_Init, dws_Kill
  1332.  
  1333.     Errors
  1334.  
  1335.     dws_ALREADYINITTED, dws_DetectHardware_UNSTABLESYSTEM, 
  1336.     dws_DetectHardware_BADBASEPORT, dws_DetectHardware_BADDMA, 
  1337.     dws_DetectHardware_BADIRQ, dws_IRQDISABLED, dws_NOTRESIDENT,
  1338.     dws_NOMEM
  1339.  
  1340.     If the machine becomes unstable more than twice, please contact
  1341.     DiamondWare!
  1342.  
  1343. dws_DGetRate
  1344.  
  1345.     Prototypes
  1346.  
  1347.     word dws_DGetRate(word *result);
  1348.     function dws_DGetRate(result : dws_WDPTR) : word;
  1349.     DECLARE FUNCTION dwsDGetRate% ALIAS
  1350.     "DWS_DGETRATE" (SEG result%)
  1351.  
  1352.     Description
  1353.  
  1354.     This function returns the sampling rate to which the hardware is
  1355.     currently set.
  1356.  
  1357.     Parameters
  1358.  
  1359.     result is a pointer to the variable that will store the current
  1360.     sampling rate.
  1361.  
  1362.     Return value
  1363.  
  1364.     Boolean success.
  1365.  
  1366.     See also
  1367.  
  1368.     dws_DGetRateFromDWD, dws_DSetRate
  1369.  
  1370.     Errors
  1371.  
  1372.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1373.     dws_NOMEM
  1374.  
  1375. dws_DGetRateFromDWD
  1376.  
  1377.     Prototypes
  1378.  
  1379.     word dws_DGetRateFromDWD(byte *snd, word *result);
  1380.     dws_DGetRateFromDWD(snd : dws_ADDRESS; result : dws_WDPTR) : word;
  1381.     DECLARE FUNCTION dwsDGetRateFromDWD% ALIAS "DWS_DGETRATEFROMDWD" 
  1382.     (BYVAL snd&, SEG result%)
  1383.  
  1384.     Description
  1385.  
  1386.     This function returns the sampling rate at which a .DWD file was
  1387.     recorded.
  1388.  
  1389.     Note: this function will work before dws_Init is called.
  1390.  
  1391.     Parameters
  1392.     
  1393.     snd is a pointer to a buffer containing a .DWD file.
  1394.  
  1395.     result is a pointer to a variable that will store the recorded
  1396.     sampling rate.
  1397.  
  1398.     Return value
  1399.  
  1400.     Boolean success.
  1401.  
  1402.     See also
  1403.  
  1404.     dws_DGetRate, dws_DSetRate
  1405.  
  1406.     Errors
  1407.  
  1408.     dws_D_NOTADWD, dws_D_NOTSUPPORTEDVER, dws_BUSY, dws_NOTRESIDENT,
  1409.     dws_NOMEM
  1410.  
  1411. dws_DPause
  1412.  
  1413.     Prototypes
  1414.  
  1415.     word dws_DPause(void);
  1416.     function dws_DPause : word;
  1417.     DECLARE FUNCTION dwsDPause% ALIAS "DWS_DPAUSE" ()
  1418.  
  1419.     Description
  1420.  
  1421.     This function pauses all digitized sound playback.
  1422.  
  1423.     Note: all calls after the first will have no effect until
  1424.     dws_DUnPause is called.  The STK does not maintain a "pause
  1425.     count".
  1426.  
  1427.     Parameters
  1428.  
  1429.     None.
  1430.  
  1431.     Return value
  1432.     
  1433.     Boolean success.
  1434.  
  1435.     See also
  1436.  
  1437.     dws_DUnPause, dws_Discard, dws_DiscardAO, dws_DClear
  1438.  
  1439.     Errors
  1440.  
  1441.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1442.     dws_NOMEM
  1443.  
  1444. dws_DPlay
  1445.  
  1446.     Prototypes
  1447.  
  1448.     word dws_DPlay(dws_DPLAY *dplay);
  1449.     function dws_DPlay(dplay : dws_DPPTR) : word;
  1450.     DECLARE FUNCTION dwsDPlay% ALIAS "DWS_DPLAY"(SEG
  1451.     dplay AS dwsDPLAY)
  1452.  
  1453.     Description
  1454.     
  1455.     This function plays a digitized sound.
  1456.  
  1457.     Parameters
  1458.     
  1459.     dplay is a pointer to a filled dws_DPLAY struct, which contains:
  1460.  
  1461.     snd      pointer to a buffer with a .DWD
  1462.     count    number of times to play; 0 means repeat indefinitely
  1463.     priority relative to other sounds; low priority snds may drop
  1464.     soundnum unique ID -- returned by the STK
  1465.     presnd   ID of sound to sequence after; 0 means don't seq
  1466.  
  1467.     Return value
  1468.  
  1469.     Boolean success.
  1470.  
  1471.     See also
  1472.  
  1473.     dws_DDiscard, dws_DDiscardAO, dws_DClear, dws_DSoundStatus
  1474.  
  1475.     Errors
  1476.  
  1477.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_D_NOTADWD,
  1478.     dws_D_NOTSUPPORTEDVER, dws_D_INTERNALERROR,
  1479.     dws_DPlay_NOSPACEFORSOUND, dws_BUSY, dws_NOTRESIDENT, dws_NOMEM
  1480.  
  1481. dws_DSetRate
  1482.  
  1483.     Prototypes
  1484.  
  1485.     word dws_DSetRate(word frequency);
  1486.     function dws_DSetRate(frequency : word) : word;
  1487.     DECLARE FUNCTION dwsDSetRate% ALIAS
  1488.     "DWS_DSETRATE" (BYVAL frequency%)
  1489.  
  1490.     Description
  1491.  
  1492.     This function sets the digitized sampling rate.  If sounds are
  1493.     currently playing, this might sound weird.  We recommend that
  1494.     you change rates only when nothing's playing.
  1495.  
  1496.     Note: some sound boards don't support every rate allowed by the
  1497.     Sound Blasters.  Many sound boards will produce an audible click
  1498.     when the rate is changed on the fly.
  1499.  
  1500.     The STK supports sampling rates from 4 KHz to 24 KHz.
  1501.  
  1502.     Parameters
  1503.  
  1504.     frequency is the new sampling rate to use.
  1505.  
  1506.     Return value
  1507.  
  1508.     Boolean success.
  1509.  
  1510.     See also
  1511.  
  1512.     dws_DGetRate, dws_DGetRateFromDWD
  1513.  
  1514.     Errors
  1515.  
  1516.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_DSetRate_FREQTOLOW, 
  1517.     dws_DSetRate_FREQTOHIGH, dws_BUSY, dws_NOTRESIDENT, dws_NOMEM
  1518.  
  1519. dws_DSoundStatus
  1520.  
  1521.     Prototypes
  1522.  
  1523.     word dws_DSoundStatus(word sndnum, word *result); function
  1524.     dws_DSoundStatus(sndnum : word; result : dws_WDPTR) : word;
  1525.     DECLARE FUNCTION dwsDSoundStatus% ALIAS "DWS_DSOUNDSTATUS"(BYVAL
  1526.     sndnum%, SEG result%)
  1527.  
  1528.     Description
  1529.  
  1530.     Internally, the STK stores each sound in a slot.  Each slot can
  1531.     hold up to two sounds -- an active sound and a sequenced sound
  1532.     (which becomes active when the currently active sound ends).
  1533.     The slot is identified by the ID of the sound playing in it.
  1534.  
  1535.     This function queries the status of a slot.
  1536.  
  1537.     Parameters
  1538.     
  1539.     sndnum is the sound's unique ID.
  1540.  
  1541.     result is a pointer to a variable to hold the returned status: 
  1542.  
  1543.     0                                         //no sound with this ID
  1544.     dws_DSTATUSCURRENT                        //sound is currently playing
  1545.     dws_DSTATUSSEQUENCED                      //sound is sequenced
  1546.     dws_DSTATUSCURRENT | dws_DSTATUSSEQUENCED //both
  1547.  
  1548.     For a slot to contain a sequenced sound, it must also hold a
  1549.     playing sound.  If you ever encounter a case where a slot
  1550.     contains only a sequenced sound, please report it to
  1551.     DiamondWare.
  1552.  
  1553.     Return value
  1554.  
  1555.     Boolean success.
  1556.  
  1557.     See also
  1558.  
  1559.     dws_DPlay
  1560.  
  1561.     Errors
  1562.  
  1563.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1564.     dws_NOMEM
  1565.  
  1566. dws_DUnPause
  1567.  
  1568.     Prototypes
  1569.  
  1570.     word dws_DUnPause(void);
  1571.     function dws_DUnPause : word;
  1572.     DECLARE FUNCTION dwsDUnPause% ALIAS "DWS_DUNPAUSE" ()
  1573.  
  1574.     Description
  1575.  
  1576.     This function resumes digitized playback, if it was previously
  1577.     paused by dws_DPause.
  1578.  
  1579.     All sounds will continue where they left off.
  1580.  
  1581.     Note: all calls after the first will have no effect until
  1582.     dws_DPause is called again.  The STK does not maintain a "pause
  1583.     count".
  1584.  
  1585.     Parameters
  1586.  
  1587.     None.
  1588.  
  1589.     Return value
  1590.  
  1591.     Boolean success.
  1592.  
  1593.     See also
  1594.  
  1595.     dws_DPause
  1596.  
  1597.     Errors
  1598.  
  1599.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1600.     dws_NOMEM
  1601.  
  1602. dws_ErrNo
  1603.  
  1604.     Prototypes
  1605.  
  1606.     word dws_ErrNo(void);
  1607.     function dws_ErrNo : word;
  1608.     DECLARE FUNCTION dwsErrNo% ALIAS "DWS_ERRNO" ()
  1609.  
  1610.     Description
  1611.     
  1612.     This function returns the last error triggered by an STK
  1613.     function.  Call it after any STK function returns false as its
  1614.     boolean success indicator.
  1615.  
  1616.     Successful STK calls do not affect the return value of dws_ErrNo.
  1617.  
  1618.     Parameters
  1619.  
  1620.     None.
  1621.  
  1622.     Return value
  1623.     
  1624.     The last STK error.
  1625.  
  1626.     See also
  1627.  
  1628.     None.
  1629.  
  1630.     Errors
  1631.  
  1632.     None.
  1633.  
  1634. dws_Init
  1635.  
  1636.     Prototypes
  1637.  
  1638.     word dws_Init(dws_DETECTRESULTS *dr, dws_IDEAL *ideal); function
  1639.     dws_Init(dr : dws_DRPTR; ideal : dws_IDPTR) : word; DECLARE
  1640.     FUNCTION
  1641.     dwsInit% ALIAS "DWS_INIT" (SEG dr AS dwsDETECTRESULTS, SEG ideal
  1642.     AS dwsIDEAL)
  1643.  
  1644.     Description
  1645.  
  1646.     This function configures and initializes the hardware and the
  1647.     STK internals.  Most STK calls won't work until after this call.
  1648.  
  1649.     The exceptions are dws_Update, dws_DetectHardWare, dws_ErrNo,
  1650.     and dws_DGetRateFromDWD.
  1651.  
  1652.     Parameters
  1653.     
  1654.     dr is a pointer to a dws_DETECTRESULTS struct that has been
  1655.     filled in by a call to dws_DetectHardWare.
  1656.  
  1657.     ideal is a pointer to a dws_IDEAL structure, which you must fill
  1658.     in with your requested settings.  The programmer might not want
  1659.     the user's sound board running to its limit, and/or the user's
  1660.     sound board may not support every feature of the STK.
  1661.  
  1662.     Note: the STK supports sample rates from 4 KHz to 24 KHz.
  1663.  
  1664.     Return value
  1665.     
  1666.     Boolean success.
  1667.  
  1668.     See also
  1669.  
  1670.     dws_DetectHardWare, dws_Kill, dws_Update
  1671.  
  1672.     Errors
  1673.  
  1674.     dws_ALREADYINITTED, dws_IRQDISABLED, dws_NOTRESIDENT, dws_NOMEM
  1675.  
  1676. dws_Kill
  1677.  
  1678.     Prototypes
  1679.  
  1680.     word dws_Kill(void);
  1681.     function dws_Kill : word;
  1682.     DECLARE FUNCTION dwsKill% ALIAS "DWS_KILL"()
  1683.  
  1684.     Description
  1685.  
  1686.     This function closes down the STK.  You must call it before your
  1687.     program terminates.
  1688.  
  1689.     Note: make sure you cover every exit path from your program,
  1690.     including DOS critical errors!  Failure to do so will leave the
  1691.     machine in a bad state.  The sound board will make noise
  1692.     forever.  The DMA controller will continue transferring.  The
  1693.     sound hardware will continue to generate IRQ's.  When the next
  1694.     program is loaded, it will overwrite the STK's Interrupt Service
  1695.     Routine (ISR)--and the machine will crash.
  1696.  
  1697.     Parameters
  1698.  
  1699.     None.
  1700.  
  1701.     Return value
  1702.     
  1703.     Boolean success.
  1704.  
  1705.     See also
  1706.  
  1707.     dws_Init, dws_DetectHardWare, dws_Update
  1708.  
  1709.     Errors
  1710.  
  1711.     dws_NOTINITTED, dws_Kill_CANTUNHOOKISR, dws_IRQDISABLED, dws_BUSY,
  1712.     dws_NOTRESIDENT, dws_NOMEM
  1713.  
  1714.     If the STK can't unhook its ISR, it probably means the user
  1715.     installed a TSR which handles the sound board's IRQ.  Whatever
  1716.     it accomplished(?), it's now preventing the STK from properly
  1717.     unhooking itself.  Tell the user to get rid of it, and call
  1718.     dws_Kill again.
  1719.  
  1720. dws_MClear
  1721.  
  1722.     Prototypes
  1723.  
  1724.     word dws_MClear(void);
  1725.     function dws_MClear : word;
  1726.     DECLARE FUNCTION dwsMClear% ALIAS "DWS_MCLEAR" ()
  1727.  
  1728.     Description
  1729.  
  1730.     This function stops music playback.
  1731.  
  1732.     Parameters
  1733.         
  1734.     None.
  1735.  
  1736.     Return value
  1737.     
  1738.     Boolean success.
  1739.  
  1740.     See also
  1741.  
  1742.     dws_MPause, dws_MPlay
  1743.  
  1744.     Errors
  1745.  
  1746.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1747.     dws_NOMEM
  1748.  
  1749. dws_MPause
  1750.  
  1751.     Prototypes
  1752.  
  1753.     word dws_MPause(void);
  1754.     function dws_MPause : word;
  1755.     DECLARE FUNCTION dwsMPause% ALIAS "DWS_MPAUSE" ()
  1756.  
  1757.     Description
  1758.  
  1759.     This function pauses music playback.
  1760.  
  1761.     Note: all calls after the first will have no effect until
  1762.     dws_MUnPause is called.  The STK does not maintain a "pause
  1763.     count".
  1764.  
  1765.     Parameters
  1766.     
  1767.     None.
  1768.  
  1769.     Return value
  1770.  
  1771.     Boolean success.
  1772.  
  1773.     See also
  1774.  
  1775.     dws_MUnPause, dws_MClear, dws_MPlay
  1776.  
  1777.     Errors
  1778.  
  1779.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1780.     dws_NOMEM
  1781.  
  1782. dws_MPlay
  1783.  
  1784.     Prototypes
  1785.  
  1786.     word dws_MPlay(dws_MPLAY *mplay);
  1787.     function dws_MPlay(mplay : dws_MPPTR) : word;
  1788.     DECLARE FUNCTION dwsMPlay% ALIAS "DWS_MPLAY" (SEG mplay AS
  1789.     dwsMPLAY)
  1790.  
  1791.     Description
  1792.  
  1793.     This function starts playing a song.
  1794.  
  1795.     Parameters
  1796.  
  1797.     mplay is a pointer to a dws_MPLAY struct, which you must fill
  1798.     in.  The fields are:
  1799.  
  1800.     track  pointer to a buffer which contains a .DWM file.
  1801.     count  number of times to play; 0 means repeat indefinitely.
  1802.  
  1803.     Return value
  1804.  
  1805.     Boolean success.
  1806.  
  1807.     See also
  1808.  
  1809.     dws_MClear, dws_MPause, dws_MSongStatus
  1810.  
  1811.     Errors
  1812.  
  1813.     dws_NOTINITED, dws_NOTSUPPORTED, dws_MPlay_NOTADWM, 
  1814.     dws_MPlay_NOTSUPPORTEDVER, dws_MPlay_INTERNALERROR, dws_BUSY,
  1815.     dws_NOTRESIDENT, dws_NOMEM
  1816.  
  1817. dws_MSongStatus
  1818.  
  1819.     Prototypes
  1820.  
  1821.     word dws_MSongStatus(word *status);
  1822.     function dws_MSongStatus(result : dws_WDPTR) : word;
  1823.     DECLARE FUNCTION dwsMSongStatus% ALIAS = "DWS_MSONGSTATUS" (SEG
  1824.     result%)
  1825.  
  1826.     Description
  1827.  
  1828.     This function returns the status of the music playback engine.
  1829.  
  1830.     Parameters
  1831.  
  1832.     result is a pointer to a variable to hold the returned status:
  1833.  
  1834.     0                                              //no song loaded
  1835.     dws_MSONGSTATUSPLAYING                         //song playing
  1836.     dws_MSONGSTATUSPAUSED                          //no song loaded,
  1837.                              STK paused
  1838.     dws_MSONGSTATUSPLAYING | dws_MSONGSTATUSPAUSED //Song loaded but
  1839.                              paused
  1840.  
  1841.     Return value
  1842.  
  1843.     Boolean success.
  1844.  
  1845.     See also
  1846.  
  1847.     dws_MPlay
  1848.  
  1849.     Errors
  1850.  
  1851.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1852.     dws_NOMEM
  1853.  
  1854. dws_MUnPause
  1855.  
  1856.     Prototypes
  1857.  
  1858.     word dws_MUnPause(void);
  1859.     function dws_MUnPause : word;
  1860.     DECLARE FUNCTION dwsMUnPause% ALIAS "DWS_MUNPAUSE" ()
  1861.  
  1862.     Description
  1863.     
  1864.     This function unpauses music paused by dws_MPause.  The music
  1865.     will continue where it left off, save that any sustaining notes
  1866.     will not start until their next key on.
  1867.  
  1868.     Note: all calls after the first will have no effect until
  1869.     dws_MPause is called again.  The STK does not maintain a "pause
  1870.     count".
  1871.  
  1872.     Parameters
  1873.  
  1874.     None.
  1875.  
  1876.     Return value
  1877.  
  1878.     Boolean success.
  1879.  
  1880.     See also
  1881.  
  1882.     dws_MPause
  1883.  
  1884.     Errors
  1885.  
  1886.     dws_NOTINITED, dws_NOTSUPPORTED, dws_BUSY, dws_NOTRESIDENT,
  1887.     dws_NOMEM
  1888.  
  1889. dws_Update
  1890.  
  1891.     Prototypes
  1892.  
  1893.     void __loadds __saveregs dws_Update(void);
  1894.     procedure dws_Update;
  1895.     SUB dwsUpdate ALIAS "DWS_UPDATE" ()
  1896.  
  1897.     Description
  1898.  
  1899.     This function keeps the STK going.  Call it regularly and frequently.
  1900.  
  1901.     If you're using the DWT, don't call dws_Update!  Everything has
  1902.     been taken care of.
  1903.  
  1904.     If you are using your own timer handler, you need to call
  1905.     dws_Update every time you get your interrupt.  dws_Update will
  1906.     load the registers it needs, and restore the caller's registers
  1907.     before returning.  Note that this function is to be called, not
  1908.     jumped to.  It returns with a retf, not an iret.
  1909.  
  1910.     Parameters
  1911.  
  1912.     None.
  1913.  
  1914.     Return value
  1915.  
  1916.     None.
  1917.  
  1918.     See also
  1919.  
  1920.     dws_Init, dwt_Init, dws_Kill, dwt_Kill
  1921.  
  1922.     Errors
  1923.  
  1924.     None
  1925.  
  1926. dws_XDig
  1927.  
  1928.     Prototypes
  1929.  
  1930.     word dws_XDig(word volume);
  1931.     function dws_XDig(volume : word) : word;
  1932.     DECLARE FUNCTION dwsXDig% ALIAS "DWS_XDIG" (BYVAL volume%)
  1933.  
  1934.     Description
  1935.     
  1936.     This function sets the digitized volume of the mixer.
  1937.  
  1938.     Note: dws_Init sets the digital volume to maximum.
  1939.  
  1940.     Parameters
  1941.  
  1942.     volume is the digitized sound level (0=min, 255=max).
  1943.  
  1944.     Return value
  1945.     
  1946.     Boolean success.
  1947.  
  1948.     See also
  1949.  
  1950.     dws_XMusic, dws_XMaster
  1951.  
  1952.     Errors
  1953.  
  1954.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_X_BADINPUT, dws_BUSY,
  1955.     dws_NOTRESIDENT, dws_NOMEM
  1956.  
  1957. dws_XMaster
  1958.  
  1959.     Prototypes
  1960.  
  1961.     word dws_XMaster(word volume);
  1962.     function dws_XMaster(volume : word) : word;
  1963.     DECLARE FUNCTION dwsXMaster% ALIAS "DWS_XMASTER" (BYVAL volume%)
  1964.  
  1965.     Description
  1966.  
  1967.     This function sets the overall volume of the mixer.
  1968.  
  1969.     Note: dws_Init sets the master volume to maximum.
  1970.  
  1971.     Parameters
  1972.     
  1973.     volume is the master sound level (0=min, 255=max).
  1974.  
  1975.     Return value
  1976.     
  1977.     Boolean success.
  1978.  
  1979.     See also
  1980.  
  1981.     dws_XDig, dws_XMusic
  1982.  
  1983.     Errors
  1984.  
  1985.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_X_BADINPUT, dws_BUSY,
  1986.     dws_NOTRESIDENT, dws_NOMEM
  1987.  
  1988. dws_XMusic
  1989.  
  1990.     Prototypes
  1991.  
  1992.     word dws_XMusic(word volume);
  1993.     function dws_XMusic(volume : word) : word;
  1994.     DECLARE FUNCTION dwsXMusic% ALIAS "DWS_XMUSIC" (BYVAL volume%)
  1995.  
  1996.     Description
  1997.  
  1998.     This function sets the music volume of the mixer.
  1999.  
  2000.     Note: dws_Init sets the music volume to maximum.
  2001.  
  2002.     Parameters
  2003.  
  2004.     volume is the music sound level (0=min, 255=max).
  2005.  
  2006.     Return value
  2007.  
  2008.     Boolean success.
  2009.  
  2010.     See also
  2011.  
  2012.     dws_XDig, dws_XMaster
  2013.  
  2014.     Errors
  2015.  
  2016.     dws_NOTINITTED, dws_NOTSUPPORTED, dws_X_BADINPUT, dws_BUSY,
  2017.     dws_NOTRESIDENT, dws_NOMEM
  2018.  
  2019. dwt_Init
  2020.  
  2021.     Prototypes
  2022.  
  2023.     void dwt_Init(word rate);
  2024.     procedure dwt_Init(rate : word);
  2025.     DECLARE SUB dwtInit ALIAS "DWT_INIT" (BYVAL rate%)
  2026.  
  2027.     Description
  2028.  
  2029.     This function initializes the timer hardware and DWT internals.
  2030.  
  2031.     Call this only if you're using the DWT.  Use the DWT only if you
  2032.     aren't reprogramming the hardware timer.
  2033.  
  2034.     None of the DWT functions will work until this function is called.
  2035.  
  2036.     Parameters
  2037.     
  2038.     rate is one of the four constants:
  2039.     dwt_18_2HZ
  2040.     dwt_36_4HZ
  2041.     dwt_72_8HZ
  2042.     dwt_145_6HZ
  2043.  
  2044.     Return value
  2045.  
  2046.     None.
  2047.  
  2048.     See also
  2049.  
  2050.     dws_Update, dwt_Kill, dwt_MasterTick
  2051.  
  2052. dwt_Kill
  2053.  
  2054.     Prototypes
  2055.  
  2056.     void dwt_Kill(void);
  2057.     procedure dwt_Kill;
  2058.     DECLARE SUB dwtKill ALIAS "DWT_KILL" ()
  2059.  
  2060.     Description
  2061.     
  2062.     This function closes down the DWT.  If you used the DWT, you
  2063.     must call dwt_Kill before your program terminates.
  2064.  
  2065.     Note: make sure you cover every exit path from your program,
  2066.     including DOS critical errors!  Failure to do so will leave the
  2067.     machine in a bad state.  When the next program is loaded, it
  2068.     will overwrite the DWT's Interrupt Service Routine (ISR)--and
  2069.     the machine will crash.
  2070.  
  2071.     Parameters
  2072.  
  2073.     None.
  2074.  
  2075.     Return value
  2076.  
  2077.     None.
  2078.  
  2079.     See also
  2080.  
  2081.     dws_Update, dwt_Init
  2082.  
  2083. dwt_MasterTick
  2084.  
  2085.     Prototypes
  2086.  
  2087.     dword dwt_MasterTick(void);
  2088.     dwt_MasterTick : longint;
  2089.     DECLARE FUNCTION dwtMasterTick& ALIAS "DWT_MASTERTICK" ()
  2090.  
  2091.     Description
  2092.     
  2093.     This function queries the value of the master timer.
  2094.  
  2095.     The master timer is reset to 0 in dwt_Init, and is incremented
  2096.     at the DWT timer rate.
  2097.  
  2098.     Parameters
  2099.  
  2100.     None.
  2101.  
  2102.     Return value
  2103.     
  2104.     Number of clock ticks since DWT was initialized.
  2105.  
  2106.     See also
  2107.  
  2108.     dwt_Init, dwt_Pause, dwt_UnPause
  2109.  
  2110. dwt_Pause
  2111.  
  2112.     Prototypes
  2113.  
  2114.     void dwt_Pause(void);
  2115.     procedure dwt_Pause;
  2116.     DECLARE SUB dwtPause ALIAS "DWT_INIT" ()
  2117.  
  2118.     Description
  2119.     
  2120.     This function pauses the master timer.
  2121.  
  2122.     Note: this does not effect music or sound playback.
  2123.  
  2124.     Note: all calls after the first will have no effect until
  2125.     dwt_UnPause is called.  The DWT does not maintain a "pause
  2126.     count".
  2127.  
  2128.     Parameters
  2129.     
  2130.     None.
  2131.  
  2132.     Return value
  2133.     
  2134.     None.
  2135.  
  2136.     See also
  2137.  
  2138.     dwt_MasterTick, dwt_UnPause
  2139.  
  2140. dwt_UnPause
  2141.  
  2142.     Prototypes
  2143.  
  2144.     void dwt_UnPause(void);
  2145.     procedure dwt_UnPause;
  2146.     DECLARE SUB dwtUnPause ALIAS "DWT_KILL" ()
  2147.  
  2148.     Description
  2149.     
  2150.     This function unpauses the master timer, if it was previously
  2151.     paused by dwt_Pause.
  2152.  
  2153.     Note: all calls after the first will have no effect until
  2154.     dwt_Pause is called again.  The STK does not maintain a "pause
  2155.     count"
  2156.  
  2157.     Parameters
  2158.     
  2159.     None.
  2160.  
  2161.     Return value
  2162.     
  2163.     None.
  2164.  
  2165.     See also
  2166.  
  2167.     dwt_Pause, dwt_MasterTick
  2168.                
  2169.                    The Errors
  2170.  
  2171. About the Error Listing
  2172. -----------------------
  2173. This section discusses every possible STK error in numerical order.
  2174. See The Functions to find the complete list of errors which may be
  2175. flagged by any given function.
  2176.  
  2177. 0.  dws_EZERO
  2178. There was no error.  You didn't need to call dws_ErrNo.
  2179.  
  2180. 1.  dws_NOTINITTED
  2181. The STK was not initialized when you called an STK function.
  2182.  
  2183. 2.  dws_ALREADYINITTED
  2184. This call cannot be made after the STK is initialized.
  2185.  
  2186. 3.  dws_NOTSUPPORTED
  2187. The installed hardware doesn't support the requested feature (music
  2188. or sound).
  2189.  
  2190. 4.  dws_DetectHardware_UNSTABLESYSTEM
  2191. This system is now unstable.  Please report this to DiamondWare.
  2192.  
  2193. 5.  dws_DetectHardware_BADBASEPORT
  2194. 6.  dws_DetectHardware_BADDMA
  2195. 7.  dws_DetectHardware_BADIRQ
  2196. You tried to override the autodetect with an irrational value for
  2197. base port, DMA channel, or IRQ level, respectively.
  2198.  
  2199. 8.  dws_Kill_CANTUNHOOKISR
  2200. After the STK initialized, the user installed a TSR which hooked the
  2201. sound board's interrupt vector.  The STK can't shut down cleanly.
  2202. Tell the user to kill the TSR.  Then call dws_Kill again.
  2203.  
  2204. 9.  dws_X_BADINPUT
  2205. You attempted to set a mixer level (digitized, music, or master) to
  2206. a value outside the range 0-255.
  2207.  
  2208. 10.  dws_D_NOTADWD
  2209. The buffer does not contain a valid .DWD file.
  2210.  
  2211. 11.  dws_D_NOTSUPPORTEDVER
  2212. This .DWD file is the wrong version.  Please reconvert using the
  2213. VOC2DWD which came with this version of the STK.
  2214.  
  2215. 12.  dws_D_INTERNALERROR
  2216. The STK encountered an invalid internal state.  Please report this
  2217. to DiamondWare.
  2218.  
  2219. 13.  dws_DPlay_NOSPACEFORSOUND
  2220. You attempted to play a low-priority sound, but all slots were in
  2221. use.  Try increasing ideal.dignvoices.  If this error occurs with
  2222. that set to 16, you're playing too many sounds too fast.  Note: this
  2223. one is a warning.  It's reasonable to flag this error occasionally.
  2224. But if it occurs immediately, or consistently, try calling dws_DPlay
  2225. less often.
  2226.  
  2227. 14.  dws_DSetRate_FREQTOLOW
  2228. 15.  dws_DSetRate_FREQTOHIGH
  2229. You attempted to set the sampling rate to an invalid frequency.  The
  2230. STK supports sampling rates from 4 KHz to 24 KHz.
  2231.  
  2232. 16.  dws_MPlay_NOTADWM
  2233. The buffer does not contain a valid .DWM file.
  2234.  
  2235. 17.  dws_MPlay_NOTSUPPORTEDVER
  2236. This .DWM file is the wrong version.  Please reconvert using the
  2237. MID2DWM which came with this version of the STK.
  2238.  
  2239. 18.  dws_MPlay_INTERNALERROR
  2240. The STK encountered an invalid internal state.  Please report this
  2241. to DiamondWare.
  2242.  
  2243. 19.  dws_BUSY
  2244. The STK is busy now.  Please call again later.  This error can only
  2245. occur if you're calling the STK from an interrupt handler.
  2246.  
  2247. 20.  dws_IRQDISABLED
  2248. You disabled IRQ's (with the CLI instruction).  IRQ's must be
  2249. enabled (with the STI instruction).
  2250.  
  2251. 100.  dws_NOTRESIDENT
  2252. The real-mode STK kernel is not resident.  This error can only occur
  2253. in protected-mode programs.
  2254.  
  2255. 101.  dws_NOMEM
  2256. The STK was unable to allocate memory.  This could be caused by
  2257. either a low-memory condition (the STK won't run the system down
  2258. to 0K) or by a lack of selectors.  This error can only occur in
  2259. protected-mode programs.
  2260.  
  2261.             The Data Structures
  2262.  
  2263. Preamble
  2264. --------
  2265. In this section, the data structures are laid out in table form.
  2266. This is done in the hope that it's easier to read than compiler
  2267. declarations.  Obviously, you can read the actual source files if
  2268. you wish.
  2269.  
  2270. Note to Pascal programmers: the following types were created to
  2271. allow the declaration of subroutines which take far pointers to
  2272. their parameters.  Declaring a function:
  2273.  
  2274. function FooBar(var x: word);
  2275.  
  2276. passes a near pointer.  The STK expects far pointers.
  2277.  
  2278. dws_DOPTR = ^dws_DETECTOVERRIDES;
  2279. dws_DRPTR = ^dws_DETECTRESULTS;
  2280. dws_IDPTR = ^dws_IDEAL;
  2281. dws_DPPTR = ^dws_DPLAYREC;
  2282. dws_MPPTR = ^dws_MPLAYREC;
  2283. dws_WDPTR = ^word;
  2284. dws_BTPTR = ^byte;
  2285.  
  2286.  
  2287. The dws_DETECTOVERRIDES struct
  2288.  
  2289. Name      Size    I/O     Description
  2290. ------------------------------------------------------
  2291. baseport  2       input   base address of sound board
  2292. digdma    2       input   DMA channel
  2293. digirq    2       input   IRQ level
  2294. reserved  10      -na-    undocumented
  2295.  
  2296.  
  2297. The dws_DETECTRESULTS struct
  2298.  
  2299. Name        Size    I/O     Description
  2300. -------------------------------------------------------------
  2301. baseport    2       output  base address of sound board
  2302. capability  2       output  bitfield of supported features
  2303. mustyp      2       output  0=none, 1=OPL2
  2304. musnchan    2       output  *1=mono
  2305. musnvoice   2       output  *number of melody voices
  2306. dignbits    2       output  +8=8 bits
  2307. dignchan    2       output  +1=mono
  2308. digdma      2       output  +digitized DMA channel
  2309. digirq      2       output  +digitized IRQ level
  2310. mixtyp      2       output  mixer type (1 software, 2+ H/W)
  2311. reserved    44      -na-    undocumented
  2312.  
  2313. * if (capability & dws_capability_FM)
  2314. + if (capability & dws_capability_DIG)
  2315.  
  2316. The dws_IDEAL struct
  2317.  
  2318. Name        Size    I/O     Description
  2319. ----------------------------------------------------------------
  2320. musictyp    2       input   music type (0 none, 1 FM)
  2321. digtyp      2       input   digitzed type (0 none, 8 8-bit dig)
  2322. digrate     2       input   sampling rate, in Hz
  2323. dignvoices  2       input   number of voices (up to 16)
  2324. dignchan    2       input   1=mono
  2325. reserved    6       -na-    undocumented
  2326.  
  2327.  
  2328. The dws_DPLAY struct
  2329.  
  2330. Name      Size      I/O       Description
  2331. -----------------------------------------------------------------
  2332. snd     *4(8)        input     pointer to buffer with .DWD in it
  2333. count     2         input     # times to play (0=infinite loop)
  2334. priority  2         input     higher numbers are higher priority
  2335. presnd    2         input     soundnum to sequence after
  2336. soundnum  2         output    unique ID
  2337. reserved  20        -na-      undocumented
  2338.  
  2339.  
  2340. The dws_MPLAY struct
  2341.  
  2342. Name      Size      I/O       Description
  2343. ----------------------------------------------------------------
  2344. track     *4(8)        input     pointer to buffer with .DWM in it
  2345. count     2         input     # times to play (0=infinite loop)
  2346. reserved  10        -na-      undocumented
  2347.  
  2348. *The number in parenthesis is the size in protected-mode.
  2349.  
  2350.              The Utilities
  2351.  
  2352. PLAYDWM
  2353. -------
  2354. PLAYDWM is a simple program to play .DWM music files.  Full source
  2355. is included with the STK.  Usage is:
  2356.  
  2357. PLAYDWM songname.dwm
  2358.  
  2359. You must type the full filename, including the .DWM.
  2360.  
  2361. PLAYDWD
  2362. -------
  2363. PLAYDWD is a simple program to play .DWD sound effect files.  Full
  2364. source is included with the STK.  Usage is:
  2365.  
  2366. PLAYDWD soundfx.dwd
  2367.  
  2368. You must type the full filename, including the .DWD.
  2369.  
  2370. FINDSB
  2371. ------
  2372. FINDSB is provided as both a simple example of how to use the STK,
  2373. and as a useful program in its own right.  Full source is included
  2374. with the STK.  It will find and print out the user's sound board
  2375. settings.  Usage is:
  2376.  
  2377. FINDSB
  2378.  
  2379. MID2DWM
  2380. -------
  2381. MID2DWM converts type 1 standard MIDI files from .MID format to .DWM
  2382. format.  It is strictly a command-line utility.  Usage is:
  2383.  
  2384. MID2DWM <rate> <midifile>[.MID] <instrfile>[.IBK] [outfile[.DWM]]
  2385.  
  2386. rate is the frequency, at which STK will get its "heartbeat" call
  2387. during run-time.  In general, the higher the rate, the more natural
  2388. the music will sound (to a limit).  If your music was performed by a
  2389. human, there are many nuances of timing which will be lost at lower
  2390. rates.
  2391.  
  2392. Note: if your program is running in a Windows DOS box, 145.6 Hz will
  2393. not work correctly (Windows will simply refuse to call you that
  2394. fast, and so the music will play slower than normal).
  2395.  
  2396. The STK includes an optional timer module which is capable of four
  2397. rates: 18.2, 36.4, 72.8, and 145.6 Hz.  If you use your own timer
  2398. code, then tell MID2DWM the rate it runs at; MID2DWM will work at
  2399. any rate.  If you're using the code supplied in the STK, use one of
  2400. those four rates only.
  2401.  
  2402. midifile is the name of the source file for the music, in MIDI type
  2403. 1 format.  The extension, .MID, is optional.
  2404.  
  2405. instrfile is the name of the instrument patch bank file, in .IBK
  2406. format.  The extension, .IBK, is optional.
  2407.  
  2408. outfile is an optional parameter, to specify the name of the output
  2409. file (if different from the source file).  The extension, .DWM, is
  2410. optional.
  2411.  
  2412. As a simple matter of managing the hundreds of files in your
  2413. project, if you keep the default file extensions for each type of
  2414. file, you'll make your life easier.
  2415.  
  2416. Examples:
  2417.  
  2418. C:\SOURCE\BANE\MUSIC mid2dwm 72.8 death gmptch
  2419. C:\SOURCE\BANE\MUSIC mid2dwm 36.4 death.mid gmptch.ibk dth1.dwm
  2420.  
  2421. MID2DWM can convert, and the STK can play, music files larger than 64K.
  2422.  
  2423. VOC2DWD
  2424. -------
  2425. VOC2DWD converts digitized sound files from .VOC format to .DWD
  2426. format.  It is strictly a command-line utility.  Usage is:
  2427.  
  2428. VOC2DWD [options] <vocfile>[.VOC] [outfile [.DWD]]
  2429.  
  2430. options are either -h, to print a help screen, or -k, to cause VOC2DWD
  2431. to keep the exact length of the VOC intact for the .DWD output.  The
  2432. default behavior will truncate to paragraph alignment.
  2433.  
  2434. vocfile is the filename of the input file, which must be in VOC
  2435. format.  The extension, .VOC, is optional.
  2436.  
  2437. outfile is an optional parameter which specifies the name of the
  2438. output file, if different from the input file.  The .DWD extension
  2439. is optional.
  2440.  
  2441. Examples:
  2442.  
  2443. C:\SOURCE\BANE\SFX voc2dwd scream
  2444. C:\SOURCE\BANE\SFX voc2dwd scream.voc sc1.dwd
  2445.  
  2446. You can use DOS wildcards to specify vocfile, as in:
  2447.  
  2448. C:\SOURCE\BANE\SFX voc2dwd *.voc
  2449.  
  2450. VOC2DWD will allow you to convert files greater than 64K; however,
  2451. this version of the STK will not play them back.  A sequencing
  2452. mechanism is offered to allow you to play long sounds, but they must
  2453. be broken up while they're in .VOC format.
  2454.  
  2455. Although .VOC files can support all sampling rates via "extended
  2456. blocks", some .VOC editors only save standard blocks.  These blocks
  2457. round to the nearest encodable rate, which can be off by up to 1
  2458. KHz.  For example, an 11 KHz .VOC file will be saved at 10989 Hz if
  2459. the sound editor only supports standard blocks.  A difference of 11
  2460. Hz is negligible to the human ear, but 1000 Hz (which happens at
  2461. higher rates) is not.  VOC2DWD supports both kinds of blocks, and
  2462. reports the true sampling rate during the conversion to help combat
  2463. this problem.
  2464.  
  2465.                  DSP
  2466.  
  2467. We provide some simple DSP for pitch and volume change of DWD files.
  2468. There are two important functions in dwdsp.c:
  2469.  
  2470.   word dwdsp_ChngVol(byte *desdwd, byte *srcdwd, word volume);
  2471.   word dwdsp_ChngLen(byte *desdwd, byte *srcdwd, dword newlen);
  2472.  
  2473. These calls change the volume of a sound, or its pitch, respectively.
  2474. Each takes a pointer to the destination buffer and the source buffer.
  2475. The third parameter to dwdsp_ChngVol specifies the new volume.  0x100
  2476. is identity, 0x80 is half volume, and 0x200 is twice as loud.  The
  2477. third parameter to dwdsp_ChngLen is the new length, in bytes.  Making
  2478. a sound longer will not only slow it down, but lower its pitch.  Making
  2479. it shorter will raise the pitch.
  2480.  
  2481. The volume change code is mathematically correct.  The pitch code, on
  2482. the other hand, is a sleazy hack which works better than it ought to.
  2483. Results range from quite acceptable, to downright lousy, depending on
  2484. listener expectations...
  2485.  
  2486. NB: You can change the volume of a sound "in place", that is pass
  2487.   desdwd == srcdwd
  2488. but you can NOT change length in place!
  2489.  
  2490. A detailed explanation of the algorithms is beyond the scope of this
  2491. document, but we'll describe basically how they work.
  2492.  
  2493. It turns out that the volume can be changed simply by multiplying
  2494. each sample by a constant.  To make a sound twice as loud, double
  2495. each sample.
  2496.  
  2497. Pitch change is a little more complex.  The pitch of a sound depends
  2498. on how fast the waveform oscillates.  dwdsp_ChngLen alters the number
  2499. of samples in the sound, thereby (indirectly) determining how fast
  2500. the sound will oscillate.  To make the sound longer, we're doubling
  2501. (or trippling, etc.) each sample.  To make it shorter, we're simply
  2502. removing samples.  This isn't the best technique, but it's fast.  It's
  2503. also easy to code. <g>
  2504.  
  2505. This code is also a good guide to the DWD specification.
  2506.  
  2507. Run playdsp.exe...
  2508.  
  2509.